#include "bunny_states.h"
#include "MessageTypes.h"
#include "Bunny.h"
#include "Messaging/MessageDispatcher.h"

void State_BunnyRun::execute(Bunny* p_bunny) {
		cout << "Execute: Run" << endl;
	
		p_bunny->m_energy = p_bunny->m_energy - 2;
		if(p_bunny->m_energy <=10) {
			p_bunny->m_stateMachine->changeState(new State_BunnyRest());
		}
	}


bool State_BunnyRun::onMessage(Bunny* p_bunny, const Telegram& p_t) {
		cout << "Bunny Handling Message" << endl;

		if(p_t.message == MSG_WOLF_StopChasing) {
			p_bunny->m_stateMachine->changeState(new State_BunnyRest);
		}

		return true;
}




void State_BunnyRest::enter(Bunny* p_bunny) {
	cout << "BUNNY: ENTER STATE Rest" << endl;
	MessageDispatcher::Instance()->dispatchMessage(2,
		p_bunny->getID(),
		id_wolf,
		MSG_BUNNY_StartResting,
		0);
}

void State_BunnyRest::execute(Bunny* p_bunny) {
		cout << "Execute: Rest" << endl;
		
		p_bunny->m_energy = p_bunny->m_energy + 5;
	}



bool State_BunnyRest::onMessage(Bunny* p_bunny, const Telegram& p_t) {
		cout << "Bunny Handling Message" << endl;

		if(p_t.message == MSG_WOLF_StartChasing) {
			p_bunny->m_stateMachine->changeState(new State_BunnyRun);
		}

		return true;
	}